<html>
  <head></head>
  <body>
    <p>reduce高级用法</p>

    <script>
      // 数组去重
      function uniqueArr(arr) {
        const newArr = arr.reduce((pre, curr) => {
          if (pre.includes(curr)) return pre
          else return pre.concat(curr)
        }, [])
        return newArr
      }

      var arr = [1, 2, 2, 3, 3, 4, 5]
      var newArr = uniqueArr(arr)
      console.log('数组去重',newArr)

// 将多维数组转成一纬数组
let arr1 = [
  [0, 1],
  [2, 3],
  9,
  [4, [5, 6, 7]],
]
function downDimensionArr(arr){
  const newArr = arr.reduce((pre,curr) => {
    const downDimCurr = Array.isArray(curr) ? downDimensionArr(curr) : curr
    return pre.concat(downDimCurr)
  },[])
  return newArr
}
var newArr1 = downDimensionArr(arr1)
console.log('将多维数组转成一纬数组',newArr1)
    </script>
  </body>
</html>
